package app.auto.runner.base.acty;

import android.app.Activity;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.List;

import app.auto.AndroidInstance;
import app.auto.runner.base.utility.ShareAlert;
import dalvik.system.DexFile;

public class DexUtil extends AndroidInstance {
    private List<String> getAllClassName() {
        List<String> classNameList = new ArrayList<String>();
        try {

            DexFile df = new DexFile(getContext().getPackageCodePath());//通过DexFile查找当前的APK中可执行文件
            Enumeration<String> enumeration = df.entries();//获取df中的元素  这里包含了所有可执行的类名 该类名包含了包名+类名的方式
            while (enumeration.hasMoreElements()) {//遍历
                String className = (String) enumeration.nextElement();
                if (className.contains("com.google") || className.contains("android.support") || className.contains("javassist.bytecode")
                        || className.contains("android") || className.contains("androidx") || className.contains("com.blankj") || className.contains("javassist") || className.contains("kotlin") || className.contains("$") || className.contains("org.reflections") || className.contains("org.intellij") || className.contains("org.jetbrains")) {
                    continue;
                }
                classNameList.add(className);
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
        return classNameList;
    }

    @Override
    public AndroidInstance use(Object mp, Object... p) {
        List list = DexUtil.get(DexUtil.class, getContext()).getAllClassName();
        ShareAlert.get(ShareAlert.class, getContext()).listAlert(list, null);
        return null;
    }
}
